<template>
  <div class="login-con">
    <el-card class="box-card">
      <div class="title-box">
        <img src="@/assets/img/logo.png" alt="" class="logo" />
        <div class="lang">
          {{lang}}
        </div>
      </div>
      <!-- 登陆表单 -->
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="account">
          <div>{{$t("lang.account")}}:</div>
          <el-input
            type="text"
            v-model="ruleForm.account"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <div>{{$t("lang.password")}}:</div>
          <el-input
            type="password"
            v-model="ruleForm.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            class="submitbtn"
            >{{$t("lang.login")}}</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>

    <div class="foot">
      <div class="foot-con">
        <img src="../../assets/img/seeed.png" alt="" class="seeed" />
        <span
          >{{$t("lang.compony")}} {{$t("lang.device")}}</span
        >
        <span>{{$t("lang.privacy")}}</span>
        <img src="../../assets/img/mcafee.png" alt="" class="mcafee" />

        <el-select
          v-model="lang"
          @change="changeLang"
          class="sel"
          :placeholder="$t('lang.lang')"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'login',
  data () {
    return {
      options: [
        {
          value: 'cn',
          label: this.$t('lang.cs')
        },
        {
          value: 'en',
          label: this.$t('lang.is')
        }
      ],
      lang: '',
      ruleForm: {
        account: '',
        password: ''
      },
      rules: {
        account: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      }
    }
  },
  methods: {
    submitForm () {
      console.log('登录函数被调用了')
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          console.log(valid)
          // 验证成功
          // 调用vuex中user子树里面的登录的action动作
          this.$store.dispatch('LoginAction', this.ruleForm)
          console.log(this.ruleForm)
        } else {
          // 验证没通过
          console.log('验证没通过')
        }
      })
    },
    // 切换语言集
    changeLang () {
      console.log('切换语言集触发了')
      this.$store.commit('SET_LANG', this.lang)
      // 刷新页面
      this.$router.go(0)
    }
  },
  created () {
    console.log(this.$store.getters.locale)
    // console.log(this.$t("lang.cs"));
    this.lang = this.$store.getters.locale
  }
}
</script>

<style scoped lang="less">
.login-con {
  .box-card {
    position: relative;
    width: 350px;
    height: 500px;
    margin: 100px auto;
    padding: 20px;
    .title-box {
      height: 80px;
      line-height: 80px;
      text-align: center;
      .logo {
        width: 140px;
      }
      .lang {
        width: 50px;
        height: 50px;
        line-height: 30px;
        padding-left: 18px;
        box-sizing:border-box;
        background-color: rgb(236, 125, 230);
        background:-webkit-linear-gradient(left bottom,rgba(0,0,0,0) 50%,blue 50%,blue 100%);
        color:white;
        position: absolute;
        top: 0;
        right: 0;
        // width: 50px;

      }
    }
    .submitbtn {
      width: 100%;
      margin-top: 50px;
    }
  }
  .foot {
    background-color: white;
    width: 100%;
    height: 50px;
    position: fixed;
    bottom: 0;
    left: 0;
    .foot-con {
      display: flex;
      height: 50px;
      width: 100%;
      justify-content: center;
      align-items: center;
      .sel {
        margin-left: 50px;
      }
    }
    span:nth-of-type(1) {
      display: block;
      width: 310px;
    }
    span {
      color: #333;
      font-size: 13px;
      margin: 10px 20px;
    }
    .seeed {
      width: 130px;
      height: 35px;
      margin-right: 50px;
    }
    .mcafee {
      height: 30px;
      margin: 50px;
    }
  }
}
</style>
